class MainPageController < ApplicationController

  def main
    @user_id = session[:user_id]
    if (@user_id == nil)
      redirect_to :controller => 'login', :action => :login
    end

    if request[:word] != nil && request[:should] != nil
      if request[:should] == "remove"
        remove(request[:word])
      end
    end

    @words = Word.find_all_by_user_id(@user_id)
  end

  def logout
    session[:user_id] = nil
    @user_id = nil
    redirect_to :controller => 'login', :action => :login
  end

  private
  def remove(id)
    word = Word.find_by_id(id)
    if word != nil && word.is_a?(Word) && word.user_id == session[:user_id]
      word.destroy
    end
  end
end
